//
//  NewsListCell.m
//  News
//
//  Created by Han on 14-5-27.
//  Copyright (c) 2014年 UCoder. All rights reserved.
//

#import "MarketCell.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation MarketCell
@synthesize leftLabel, middleLabel, rightButton, rightLabel, line;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        //self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self drawView];
    }
    return self;
}


-(void)drawView
{
    leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 50)];
    leftLabel.numberOfLines = 2;
    leftLabel.backgroundColor = [UIColor clearColor];
    //leftLabel.text = @"上证指数";
    [self.contentView addSubview:leftLabel];
    /*
    self.upDownBgview = [[UIView alloc]initWithFrame:CGRectMake(kVIEW_BX(_titleLabel), 7, (kVIEW_W(self)-2*kLEFT_SPACE)/3-20, cellheight - 14)];
    self.upDownBgview.alpha = 0;
    [self.contentView addSubview:self.upDownBgview];
     
     */
    middleLabel = [[UILabel alloc] initWithFrame:CGRectMake(GET_LEFT_X(leftLabel), 0, 100, 50)];
    middleLabel.textColor = [UIColor blackColor];
    middleLabel.font = [UIFont fontWithName:@"Avenir-Heavy" size:16.0f];
    middleLabel.textAlignment = NSTextAlignmentCenter;
    middleLabel.numberOfLines = 2;
    middleLabel.backgroundColor = [UIColor clearColor];
    //middleLabel.text = @"1.3513";
    [self.contentView addSubview:middleLabel];
     
    
    rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(GET_LEFT_X(middleLabel) + 11, 7, 78, 50 - 14);
    rightButton.backgroundColor = [UIColor greenColor];
    rightButton.layer.cornerRadius = 3.0;
    [self.contentView addSubview:rightButton];
    
    
    rightLabel = [[UILabel alloc]initWithFrame:rightButton.frame];
    rightLabel.backgroundColor = [UIColor clearColor];
    rightLabel.font = [UIFont fontWithName:@"Avenir-Heavy" size:16.0f];
    rightLabel.textAlignment = NSTextAlignmentCenter;
    //rightLabel.text = @"-0.0011";
    [self.contentView addSubview:rightLabel];
    
    /*
    _line = [[UIView alloc]initWithFrame:CGRectMake(kLEFT_SPACE, cellheight-0.5, kVIEW_W(self)-2*kLEFT_SPACE, 0.5)];
    [self.contentView addSubview:_line];
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor blackColor];
    self.selectedBackgroundView = view;
    _selectionBgView = view;
    [self addThemeChanged];
    [self resetMode];
    //    _titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _bgButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _openRateLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    _upDownBgview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
     */
    
    line = [[UIView alloc]initWithFrame:CGRectMake(10, 50-0.5, 320, 0.5)];
    [self.contentView addSubview:line];
    
    line.backgroundColor = [UIColor lightGrayColor];
    
}

- (void)setMarket:(Market *)market {
    
    leftLabel.text = market.title;
    middleLabel.text = market.open;
    rightLabel.text = market.prevClose;
    /*
    _newsTitle.text = news.title;
    
    [_newsImg sd_setImageWithURL:[NSURL URLWithString:news.imgUrl]
                   placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
     */
}


- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    if (selected) {
        // 点击时背景设置
        //self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
        //self.selectedBackgroundView.backgroundColor = [UIColor darkGrayColor];
    }
    
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"++++++++++");
}

@end
